﻿using ConfExpert.Forms.ImportWizards;
using System;
using DevTeam;
using System.Collections.Generic;
using System.Data;
using System.IO;

namespace ConfExpert.Forms.Siparisler.BOM
{
    public partial class HolyFashion : XIBOM
    {
        public HolyFashion()
        {
            InitializeComponent();
            this.Init("Holy Fashion BOM", true);
            this.FileDone += HolyFashion_FileDone;
        }

        void HolyFashion_FileDone(DataSet ds, string FileName)
        {
            foreach (DataTable dt in ds.Tables)
            {
                DataRowCollection rows = dt.Rows;
                DataColumnCollection cols = dt.Columns;

                Dictionary<string, int> indexes = new Dictionary<string, int>();

                DataRow dr0 = dt.Rows[3];
                for (int colIndex = 0; colIndex < dt.Columns.Count; colIndex++)
                {
                    switch (dr0[colIndex].ToString())
                    {
                        case "Item no.":
                        case "Item no. ": indexes.Add("ItemNr", colIndex); break;
                        case "Material": indexes.Add("Material", colIndex); break;
                        case "Material Description": indexes.Add("MaterialDescription", colIndex); break;
                        case "Item Text 1": indexes.Add("ItemText1", colIndex); break;
                        case "Usage Descrip.":
                        case "Usage Description": indexes.Add("UsageDescription", colIndex); break;
                        case "CAD Ind.": indexes.Add("CADInd", colIndex); break;
                        case "Comp. Quant.":
                        case "Comp. Quantity": indexes.Add("CompQuantity", colIndex); break;
                        case "Unit": indexes.Add("Unit", colIndex); break;
                        case "Fix col.":
                        case "Fix color": indexes.Add("FixColor", colIndex); break;
                        case "col. 1":
                        case "color 1": indexes.Add("Color1", colIndex); break;
                        case "col. 2":
                        case "color 2": indexes.Add("Color2", colIndex); break;
                        case "col. 3":
                        case "color 3": indexes.Add("Color3", colIndex); break;
                        case "col. 4":
                        case "color 4": indexes.Add("Color4", colIndex); break;
                        case "col. 5":
                        case "color 5": indexes.Add("Color5", colIndex); break;
                        case "col. 6":
                        case "color 6": indexes.Add("Color6", colIndex); break;
                        case "col. 7":
                        case "color 7": indexes.Add("Color7", colIndex); break;
                        case "col. 8":
                        case "color 8": indexes.Add("Color8", colIndex); break;
                        case "col. 9":
                        case "color 9": indexes.Add("Color9", colIndex); break;
                        case "col. 10":
                        case "color 10": indexes.Add("Color10", colIndex); break;
                        case "col. 11":
                        case "color 11": indexes.Add("Color11", colIndex); break;
                        case "col. 12":
                        case "color 12": indexes.Add("Color12", colIndex); break;
                        case "col. 13":
                        case "color 13": indexes.Add("Color13", colIndex); break;
                        case "col. 14":
                        case "color 14": indexes.Add("Color14", colIndex); break;
                        case "col. 15":
                        case "color 15": indexes.Add("Color15", colIndex); break;
                        case "Fix size": indexes.Add("FixSize", colIndex); break;
                        case "Vendor Material Number": indexes.Add("VendorMaterialNumber", colIndex); break;
                        case "Vendor Name": indexes.Add("VendorName", colIndex); break;
                        case "MP": indexes.Add("MP", colIndex); break;
                    }
                }

                if (dt.Rows[2][0].ToStr() != string.Empty)
                {
                    DataRow drBOM = BOM.NewRow();
                    drBOM["DosyaAdi"] = dt.Rows[2]["DosyaAdi"];
                    drBOM["MaterialNr"] = dt.Rows[2][0].ToStr();
                    drBOM["Style"] = dt.Rows[2][3].ToStr();
                    drBOM["Phase"] = dt.Rows[2][4].ToStr();
                    drBOM["Division"] = dt.Rows[2][6].ToStr();
                    BOM.Rows.Add(drBOM);

                    for (int i = 4; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = rows[i];
                        if (dr[indexes["Material"]].ToStr() != string.Empty)
                        {
                            DataRow drBOMLines = BOMLines.NewRow();
                            drBOMLines["DosyaAdi"] = dr["DosyaAdi"];
                            foreach (KeyValuePair<string, int> entry in indexes)
                                drBOMLines[entry.Key] = dr[indexes[entry.Key]];
                            BOMLines.Rows.Add(drBOMLines);
                        }
                    }
                }
            }


        }

    }
}
